import { Injectable } from '@angular/core';
import { BefRepository, ResponseInfo } from '@farris/bef';
import { CommandService } from '@farris/command-services';
import { FrameContext } from '@farris/devkit';

@Injectable()
export class GzsqDetailFrmControllerService {
  constructor(
    private frameContext: FrameContext,
    private commandService: CommandService
  ) {}

  /**
   * 新增台账列表
   * @remarks 
   * @returns 
   */
  addTzList(): any {
    let checkedList = this.frameContext.uiState['checkedList']

    let id = this.frameContext.bindingData.getValue(['id'])

    const rep = this.frameContext.repository as BefRepository<any>;
    let datas  = []

    let componentName = 'gzsqDetail-teqk-component';
    let gzmxName = 'yjmx-component'
    let nowIdList = this.frameContext.appContext.componentManager.get([componentName + '_gzsqdetail_' + gzmxName,'dataGrid_yjmx']).data.map(i=>i.gzid.gzid)

    checkedList.forEach(i=>{
      let d = i.data
      
      let has = nowIdList.some(c => {
        if(d.id == c){
          return true
       }
       return false
      })

      console.log(d)
      if (!has){
        datas.push({
            gzid: {
              gzid: d.id,
              gzid_bzmc:d.bzmc,
              gzid_bmid_name:d.bmid.bmid_name,
              gzid_bzgg:d.bzgg,
              gzid_zmsl:d.zmsl,
              gzid_sdsl:d.sdsl,
              gzid_dw:d.dw,
              gzid_zrr_code:d.zrr.zrr_code,
              gzid_zrr_name:d.zrr.zrr_name
            }
          })
      }
    })


    rep.batchAppendByPath('/' + id + '/yjmxs',datas).subscribe()
  }

  /**
   * 刷新列表
   */
  reflashData(){
    const result = this.commandService.execute("Filter1","root-component");
  }
}
